/*
 * Created by JFormDesigner on Thu May 20 15:31:01 CST 2021
 */

package com.dfrz.bookstore.view;

import java.awt.event.*;
import java.beans.*;
import javax.swing.border.BevelBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.event.*;
import javax.swing.table.*;

import com.dfrz.bookstore.entry.*;
import com.dfrz.bookstore.service.BookTypeService;
import com.dfrz.bookstore.service.ShoppingCarService;
import com.dfrz.bookstore.service.impl.*;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;



/**
 * @author keyan
 */
public class Client extends JFrame {
//    public static Client client=null;
    BookServiceImpl bookService = new BookServiceImpl();
    ShoppingCarService carService = new ShoppingCarServiceImpl();
    OrderServiceImpl orderService = new OrderServiceImpl();
    IdeaServiceImpl ideaService = new IdeaServiceImpl();
    BookTypeServiceImpl typeService = new BookTypeServiceImpl();
    User user = null;//当前用户
    Book book = null;//当前图书
    ShoppingCar shoppingCar =null;//当前购物车
    List<Book> bookList ;
    public Client(User user, Book book) {
        initComponents();
        /*设置滚动条滚动量*/
        scrollPane2.getVerticalScrollBar().setUnitIncrement(15);
        ImageIcon icon = null;
        try {
            icon = new ImageIcon(new URL(user.getUserImage()));
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        //改变图片大小
        //80和100为大小 可以自由设置
        icon.setImage(icon.getImage().getScaledInstance(50,50,Image.SCALE_DEFAULT));

        userImg.setIcon(icon);
        this.user = user;
        this.book = book;
        setTitle("KY在线书店  "+user.getName()+"欢迎您" );
        selectBookType();
        showLevel.setText(String.valueOf(user.getLevel()));
        showBookList(book,1);
//        ============购物车展示===============================
        shoppingCar = new ShoppingCar();
        showCar(shoppingCar);

        Order order = new Order();
        showOrder(order);
        showIdea();//渲染用户意见表格
        F5.addActionListener(e -> F5ActionPerformed(e,2));
        F5_1.addActionListener(e -> F5ActionPerformed(e,1));
        F6.addActionListener(e -> F5ActionPerformed(e,3));
        F7.addActionListener(e -> F5ActionPerformed(e,0));
    }


    /**
     * 用户意见
     */
    private void showIdea(){
        Idea idea = new Idea();
        idea.setUserId(user.getId());
        String[] s = new String[]{"标题","内容","发送时间"};
        List<Idea> ideaList = ideaService.findIdeaByIdea(idea);
        Object[][] objects = new Object[ideaList.size()][s.length];

        for (int i = 0; i < ideaList.size(); i++) {
            Idea idea1=ideaList.get(i);
            Object[] objects1 = new Object[]{idea1.getTitle(),idea1.getContent(),idea1.getSend_time()};
            objects[i]=objects1;
        }
        //---- table3 ----
        table3.setModel(new DefaultTableModel(objects,s));
        scrollPane4.setViewportView(table3);
    }

    /**
     * 订单列表(表格做的)
     */
    JTable table1 ;
    public void showOrder(Order order ){
        ClientPane1.setBackground(new Color(186, 222, 204));
        bookpanel.setBackground(new Color(186, 222, 204, 69));
        showBookJpanel.setBackground(new Color(186, 222, 204, 69));
        order.setUser_id(user.getId());
        List<Order> orderList = orderService.findOrderByOrder(order);

        Object[][] objects = new Object[orderList.size()][2];

        for (int i=0;i<orderList.size();i++){
            Order order1=orderList.get(i);
            Object[] objects1 = new Object[2];
            int status = order1.getStatus();
            if(status==0){
                objects1 = new Object[]{order1.getOrder_item_id(), "未发货"};
            }else if(status==1){
                objects1 = new Object[]{order1.getOrder_item_id(), "已发货"};
            }else if(status==2){
                objects1 = new Object[]{order1.getOrder_item_id(), "已收货"};
            }else if(status==3){
                objects1 = new Object[]{order1.getOrder_item_id(), "已退货"};
            }


            objects[i]=objects1;
        }

        String[] titles = {"订单号","订单状态"};
        table1 = new JTable();
        table1.setModel(new DefaultTableModel(objects,titles));
        table1.setSelectionBackground(new Color(0,0,0));
        table1.setRowHeight(30);
        table1.setSelectionForeground(new Color(255,255,255));
        table1.setFont(new Font("黑体", Font.BOLD,20));
        table1.setShowGrid(false);
        /*添加监听事件*/
        table1.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                OrderTableMouseClicked(e);
            }
        });
        scrollPane3.setViewportView(table1);
    }

    List<JPanel> jPanelList = new ArrayList<>();//存储首页的图书框
    /**
     * 渲染图书
     * @param book
     * @param pageNum
     */
    public  void showBookList(Book book,int pageNum){
        bookList = bookService.findBookByPage(book, pageNum, 8);
        if (jPanelList.size()>0){
            closeShowBookJpanel();
            repaint();
            showBookJpanel.updateUI();
        }
        /*查找上架的图书总数*/
        int count = bookService.findCount(book,user);

        for (Book book1 : bookList) {
            JPanel jPane_show = addItem(new JPanel(), book1, showBookJpanel);
            jPanelList.add(jPane_show);
        }

        currentPage.setText(String.valueOf(pageNum));
        int totalPage_ = 0;
        /*计算总页码*/
        if (count%8==0){
            totalPage_ = count/8;
        }else {
            totalPage_ = count/8+1;
        }
        totalPage.setText(String.valueOf(totalPage_));
    }

    /**
     * 渲染购物车
     * @param shoppingCar
     */
    public void showCar(ShoppingCar shoppingCar){
        shoppingCar.setUserId(user.getId());
        //每次调用showCar 要清空复选框集合
        checkBoxes  = new ArrayList<>();
        List<ShoppingCar> carList = carService.findCarByCar(shoppingCar);

        for (int i = 0; i < carList.size(); i++) {
            addCar(carList.get(i),i);
        }

        { // compute preferred size
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < carPanel.getComponentCount(); i++) {
                Rectangle bounds = carPanel.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = carPanel.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            carPanel.setMinimumSize(preferredSize);
            carPanel.setPreferredSize(preferredSize);
        }
    }
    /**
     * 清空网格布局里面的数据
     */
    public void closeShowBookJpanel(){
        showBookJpanel.removeAll();
    }

    /**
     * 退出登录
     * @param e
     */
    private void exitButtonActionPerformed(ActionEvent e) {

        int i = JOptionPane.showConfirmDialog(null, "确认退出吗?", "标题", JOptionPane.YES_NO_OPTION);
        if (i==0){
            Login login = new Login();
            login.setVisible(true);
            //关闭客户端
            dispose();
        }
    }

    /**
     *订单表中单击订单 跳转至对应的订单项
     * @param e
     */
    private void OrderTableMouseClicked(MouseEvent e) {
        Object valueAt = table1.getValueAt(table1.getSelectedRow(),0);
        String itemID = (String)valueAt;
        Order order = new Order();
        order.setOrder_item_id(itemID);
        order = orderService.findOrderByOrder(order).get(0);
        OrderItemView orderItemView = new OrderItemView(order,user);
        orderItemView.setVisible(true);
    }

    /**
     *首页的图书被点击 打开书本详情
     * @param e
     * @param book
     * @param user
     */
    private void itemMouseClicked(MouseEvent e,Book book,User user) {
        BookInfo bookInfo = new BookInfo(book,user);
        bookInfo.setVisible(true);
        setVisible(false);
    }
    /**
     * 动态添加 窗体 展示图书
     * @param item
     * @param book
     * @param showBookJpanel
     */
    public JPanel addItem(JPanel item, Book book,JPanel showBookJpanel ){
        //======== item ========
        {
            item.setForeground(new Color(238, 238, 238));
            item.setBackground(UIManager.getColor("Button.default.shadowColor"));
//            item.setBorder(new BevelBorder(BevelBorder.LOWERED));
            item.setLayout(null);
            /*添加监听事件*/
            item.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    itemMouseClicked(e,book,user);
                }
            });

            //---- img ----
            ImageIcon icon = null;
            try {
                icon = new ImageIcon(new URL(book.getImg_src()));
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
            //改变图片大小
            //80和100为大小 可以自由设置
            icon.setImage(icon.getImage().getScaledInstance(145,180,Image.SCALE_DEFAULT));
            JLabel img = new JLabel();
            img.setIcon(icon);
            item.add(img);
            img.setBounds(39, 10, 145, 180);

            //---- author ----
            JLabel author = new JLabel();
            author.setFont(new Font("方正字迹-叶根友特楷简体", label2.getFont().getStyle(), label2.getFont().getSize() + 2));
            author.setHorizontalAlignment(SwingConstants.CENTER);
            author.setText(book.getAuthor());
            item.add(author);
            author.setBounds(50, 193, 140, author.getPreferredSize().height);

            //---- price ----
            JLabel price = new JLabel();
            price.setFont(new Font("黑体", label2.getFont().getStyle(), label2.getFont().getSize() + 2));
            price.setHorizontalAlignment(SwingConstants.CENTER);
            price.setText(book.getPrice()+"$");
            item.add(price);
//            price.setBounds(new Rectangle(new Point(70, 215), price.getPreferredSize()));
            price.setBounds(50, 215,140, 15);

            //---- bookName ----
            JLabel bookName = new JLabel();
            bookName.setFont(new Font("方正字迹-叶根友特楷简体", label2.getFont().getStyle(), label2.getFont().getSize() + 7));
            bookName.setHorizontalAlignment(SwingConstants.CENTER);
            bookName.setText(book.getName());
            item.add(bookName);
            bookName.setBounds(50, 230,140, 15);

            { // compute preferred size
                Dimension preferredSize = new Dimension();
                for(int i = 0; i < item.getComponentCount(); i++) {
                    Rectangle bounds = item.getComponent(i).getBounds();
                    preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                    preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                }
                Insets insets = item.getInsets();
                preferredSize.width += insets.right;
                preferredSize.height += insets.bottom;
                item.setMinimumSize(preferredSize);
                item.setPreferredSize(preferredSize);
            }
        }
        showBookJpanel.add(item);
        return item;
    }

    List<JCheckBox> checkBoxes ;

    /**动态添加购物车
     *
     * @param i
     */
    public void addCar(ShoppingCar shoppingCar,int i ){
        JCheckBox carID = new JCheckBox();
        JLabel   img = new JLabel();
        JLabel   bookName = new JLabel();
        JLabel   price = new JLabel();
        JSpinner  spinner1 = new JSpinner();
        //查找出对应的书本
        Book book1 = new Book();
        book1.setId(shoppingCar.getBookId());
        List<Book> bookList2 = bookService.findBookByBook(book1);
        Book book2 = bookList2.get(0);
        if (book2==null){
            JOptionPane.showMessageDialog(null,"购物车中的  "+book2.getName()+"  图书被下架了");
            return;
        }
         //---- carID ----
        carID.setText(String.valueOf(shoppingCar.getId()));
        carPanel.add(carID);
        carID.setBounds(new Rectangle(new Point(10, 60+(i*160)), carID.getPreferredSize()));
        checkBoxes.add(carID);
        //---- img ----

        ImageIcon icon = null;
        try {
            icon = new ImageIcon(new URL(book2.getImg_src()));
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
//        改变图片大小
//        80和100为大小 可以自由设置
        icon.setImage(icon.getImage().getScaledInstance(115,140,Image.SCALE_DEFAULT));
        img.setIcon(icon);
        carPanel.add(img);
        img.setBounds(65, 10+(i*160), 115, 140);

        //---- bookName ----
        bookName.setText(shoppingCar.getBookName());
        carPanel.add(bookName);
        bookName.setBounds(185, 10+(i*160), 75, bookName.getPreferredSize().height);

        //---- price ----
        price.setText(String.valueOf(shoppingCar.getBookPrice()));
        carPanel.add(price);
        price.setBounds(new Rectangle(new Point(185, 60+(i*160)), price.getPreferredSize()));

        spinner1.setModel(new SpinnerNumberModel(shoppingCar.getBookNum(), 1,book2.getStore(), 1));
        spinner1.addChangeListener(e -> spinner1ChangeList(e,spinner1,carID.getText()));
        carPanel.add(spinner1);
        spinner1.setBounds(new Rectangle(new Point(250, 60+(i*160)), spinner1.getPreferredSize()));


    }

    /**
     *监听购物车的数量 发生改变时候
     * @param e
     */
    private void spinner1ChangeList(ChangeEvent e,JSpinner spinner,String carId) {
        Object value = spinner.getValue();
        ShoppingCar shoppingCar = new ShoppingCar();
        shoppingCar.setId(Integer.valueOf(carId));
        shoppingCar.setBookNum((int)value);
        carService.upDataShoppingCar(shoppingCar);

    }

    /**
     * 点击上一页
     * @param e
     */
    private void previousPageActionPerformed(ActionEvent e) {
        // TODO add your code here
        if (Integer.valueOf(currentPage.getText())==1){
            JOptionPane.showMessageDialog(null,"当前为第一页");
            return;
        }
        showBookList(book,Integer.valueOf(currentPage.getText())-1);
//        showBookJpanel.removeAll();
//        repaint();
    }
    /**
     * 点击下一页
     * @param e
     */
    private void nextPageActionPerformed(ActionEvent e) {
        // TODO add your code here
        if (Integer.valueOf(currentPage.getText())==Integer.valueOf(totalPage.getText())){
            JOptionPane.showMessageDialog(null,"当前为最后一页");
            return;
        }
        showBookList(book,Integer.valueOf(currentPage.getText())+1);
//        repaint();
    }
    //跳转第一页
    private void FirstPageActionPerformed(ActionEvent e) {
        // TODO add your code here
        showBookList(book,1);
//        repaint();
    }
    //跳转最后一页
    private void endPageActionPerformed(ActionEvent e) {
        // TODO add your code here
        showBookList(book,Integer.valueOf(totalPage.getText()));
//        showBookJpanel.removeAll();
//        repaint();
    }
    /**关闭窗体时触发
     *
     * @param e
     */
    private void thisWindowClosed(WindowEvent e) {
        setVisible(false);
    }

    /**购物车全选按钮
     * @param e
     */
    private void selectAllActionPerformed(ActionEvent e) {
        if (selectAll.isSelected()){
            for (JCheckBox box : checkBoxes) {
                box.setSelected(true);
            }
            selectAll.setText("取消全选");
        }else {
            for (JCheckBox box : checkBoxes) {
                box.setSelected(false);
            }
            selectAll.setText("全选");
        }
    }

    /**结算按钮 遍历
     * @param e
     */
    private void addOrderActionPerformed(ActionEvent e) {

        //把购物车中 选中的项存入集合cars中
        ArrayList<ShoppingCar> cars = new ArrayList<>();
        for (JCheckBox box : checkBoxes) {
            if (box.isSelected()){
                ShoppingCar car = new ShoppingCar();
                car.setId(Integer.valueOf(box.getText()));
                cars.add(carService.findCarByCar(car).get(0));
            }
        }

        Pay pay = new Pay(user,cars);
        pay.setVisible(true);
        setVisible(false);

    }
    /**
     * 购物车删除选中
     * @param e
     */
    private void delCarActionPerformed(ActionEvent e) {

        //确认是否要删除
        int opt = JOptionPane.showConfirmDialog(null,
                "请确认你要删除的订单项吗?", "确认信息",
                JOptionPane.YES_NO_OPTION);
        if (opt == JOptionPane.YES_OPTION) {
            //确认继续操作
            for (JCheckBox box : checkBoxes) {
                if (box.isSelected()){
                    carService.delectShoppingCarById(Integer.valueOf(box.getText()));
                }
            }

        }
        dispose();
        Client client = new Client(user, book);
        client.ClientPane1.setSelectedIndex(1);
        client.setVisible(true);
    }

    /**搜索图书
     *
     * @param e
     */
    private void searchActionPerformed(ActionEvent e) {
        // TODO add your code here
        book.setName(searchBar.getText());
        showBookList(book,1);
    }

    /**用户注册
     *
     * @param e
     */
    private void reviseActionPerformed(ActionEvent e) {
        UserRegistration userRegistration = new UserRegistration(user);
        userRegistration.setVisible(true);
    }

    /**
     * 意见提交
     * @param e
     */
    private void ideaSubmitActionPerformed(ActionEvent e) {
        // TODO add your code here
        Idea idea = new Idea();
        idea.setTitle(ideaTitle.getText());
        idea.setContent(ideaContent.getText());
        idea.setUserId(user.getId());
        ideaService.insertIdea(idea);
        dispose();
        Client client = new Client(user, book);
        client.ClientPane1.setSelectedIndex(3);
        client.setVisible(true);
    }

    /**刷新按钮
     *
     * @param e
     * @param i
     */
    private void F5ActionPerformed(ActionEvent e,int i) {
        dispose();
        setVisible(false);
        Book book1 = new Book();
        book1.setFlag(1);
        Client client = new Client(user,book1);
        client.ClientPane1.setSelectedIndex(i);
        client.setVisible(true);
    }


    JComboBox<Object> selectType ;
    /**
     * 图书分类盒子
     */
    private void selectBookType(){
        List<BookType> typeList = typeService.findAllBookType();

        String[] types = new String[typeList.size()];
        for (int i = 0; i <typeList.size() ; i++) {
            types[i] = typeList.get(i).getType();
        }
        selectType = new JComboBox<>();
        selectType.setModel(new DefaultComboBoxModel<>(types));
        selectType.addActionListener(e -> selectTypeActionPerformed(e));
        bookpanel.add(selectType);
        selectType.setBounds(80, 15, 128, selectType.getPreferredSize().height);
    }

    private void selectTypeActionPerformed(ActionEvent e) {
//        System.out.println(selectType.getSelectedItem());

        int id = typeService.findTypeIDByType(String.valueOf(selectType.getSelectedItem()));
//        Book book1 = new Book();
//        book1.setFlag(1);
//        book1.setType_id(id);
//        showBookList(book1,1);

        book.setType_id(id);
        showBookList(book,1);
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        ClientPane1 = new JTabbedPane();
        bookpanel = new JPanel();
        showBookJpanel = new JPanel();
        FirstPage = new JButton();
        previousPage = new JButton();
        nextPage = new JButton();
        endPage = new JButton();
        label13 = new JLabel();
        currentPage = new JLabel();
        label1 = new JLabel();
        showLevel = new JLabel();
        label2 = new JLabel();
        totalPage = new JLabel();
        label4 = new JLabel();
        searchBar = new JTextField();
        search = new JButton();
        userImg = new JLabel();
        F7 = new JButton();
        carpanel = new JPanel();
        scrollPane2 = new JScrollPane();
        carPanel = new JPanel();
        addOrder = new JButton();
        delCar = new JButton();
        F5_1 = new JButton();
        selectAll = new JRadioButton();
        orderpanel = new JPanel();
        scrollPane3 = new JScrollPane();
        F5 = new JButton();
        ideapanel = new JPanel();
        ideaSubmit = new JButton();
        scrollPane1 = new JScrollPane();
        ideaContent = new JTextArea();
        scrollPane4 = new JScrollPane();
        table3 = new JTable();
        textArea2 = new JTextArea();
        ideaTitle = new JTextField();
        label3 = new JLabel();
        label5 = new JLabel();
        F6 = new JButton();
        panel1 = new JPanel();
        exitButton = new JButton();
        revise = new JButton();

        //======== this ========
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosed(WindowEvent e) {
                thisWindowClosed(e);
            }
        });
        Container contentPane = getContentPane();
        contentPane.setLayout(null);

        //======== ClientPane1 ========
        {

            //======== bookpanel ========
            {
                bookpanel.setLayout(null);

                //======== showBookJpanel ========
                {
                    showBookJpanel.setLayout(new GridLayout(2, 4));
                }
                bookpanel.add(showBookJpanel);
                showBookJpanel.setBounds(50, 60, 925, 530);

                //---- FirstPage ----
                FirstPage.setText("\u7b2c\u4e00\u9875");
                FirstPage.addActionListener(e -> FirstPageActionPerformed(e));
                bookpanel.add(FirstPage);
                FirstPage.setBounds(95, 615, FirstPage.getPreferredSize().width, 29);

                //---- previousPage ----
                previousPage.setText("\u4e0a\u4e00\u9875");
                previousPage.addActionListener(e -> previousPageActionPerformed(e));
                bookpanel.add(previousPage);
                previousPage.setBounds(265, 615, 78, 30);

                //---- nextPage ----
                nextPage.setText("\u4e0b\u4e00\u9875");
                nextPage.addActionListener(e -> nextPageActionPerformed(e));
                bookpanel.add(nextPage);
                nextPage.setBounds(660, 610, 78, 30);

                //---- endPage ----
                endPage.setText("\u5c3e\u9875");
                endPage.addActionListener(e -> endPageActionPerformed(e));
                bookpanel.add(endPage);
                endPage.setBounds(850, 610, 78, 30);

                //---- label13 ----
                label13.setText("\u5f53\u524d\u9875:");
                bookpanel.add(label13);
                label13.setBounds(425, 620, 50, label13.getPreferredSize().height);

                //---- currentPage ----
                currentPage.setText("1");
                bookpanel.add(currentPage);
                currentPage.setBounds(490, 620, 30, currentPage.getPreferredSize().height);

                //---- label1 ----
                label1.setText("\u4e66\u57ce\u7b49\u7ea7:");
                bookpanel.add(label1);
                label1.setBounds(920, 5, 65, 25);

                //---- showLevel ----
                showLevel.setText("level");
                bookpanel.add(showLevel);
                showLevel.setBounds(985, 10, 30, showLevel.getPreferredSize().height);

                //---- label2 ----
                label2.setText("\u5171");
                bookpanel.add(label2);
                label2.setBounds(new Rectangle(new Point(525, 620), label2.getPreferredSize()));

                //---- totalPage ----
                totalPage.setText("text");
                bookpanel.add(totalPage);
                totalPage.setBounds(new Rectangle(new Point(545, 620), totalPage.getPreferredSize()));

                //---- label4 ----
                label4.setText("\u9875");
                bookpanel.add(label4);
                label4.setBounds(new Rectangle(new Point(575, 620), label4.getPreferredSize()));

                //---- searchBar ----
                searchBar.setText("\u7ea2\u697c\u68a6");
                bookpanel.add(searchBar);
                searchBar.setBounds(320, 10, 370, 35);

                //---- search ----
                search.setText("\u641c\u7d22");
                search.addActionListener(e -> searchActionPerformed(e));
                bookpanel.add(search);
                search.setBounds(new Rectangle(new Point(700, 10), search.getPreferredSize()));
                bookpanel.add(userImg);
                userImg.setBounds(5, 5, 50, 50);

                //---- F7 ----
                F7.setText("\u8fd4\u56de");
                bookpanel.add(F7);
                F7.setBounds(225, 15, 78, 30);

                { // compute preferred size
                    Dimension preferredSize = new Dimension();
                    for(int i = 0; i < bookpanel.getComponentCount(); i++) {
                        Rectangle bounds = bookpanel.getComponent(i).getBounds();
                        preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                        preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                    }
                    Insets insets = bookpanel.getInsets();
                    preferredSize.width += insets.right;
                    preferredSize.height += insets.bottom;
                    bookpanel.setMinimumSize(preferredSize);
                    bookpanel.setPreferredSize(preferredSize);
                }
            }
            ClientPane1.addTab("\u56fe\u4e66", bookpanel);

            //======== carpanel ========
            {
                carpanel.setLayout(null);

                //======== scrollPane2 ========
                {

                    //======== carPanel ========
                    {
                        carPanel.setLayout(null);

                        { // compute preferred size
                            Dimension preferredSize = new Dimension();
                            for(int i = 0; i < carPanel.getComponentCount(); i++) {
                                Rectangle bounds = carPanel.getComponent(i).getBounds();
                                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                            }
                            Insets insets = carPanel.getInsets();
                            preferredSize.width += insets.right;
                            preferredSize.height += insets.bottom;
                            carPanel.setMinimumSize(preferredSize);
                            carPanel.setPreferredSize(preferredSize);
                        }
                    }
                    scrollPane2.setViewportView(carPanel);
                }
                carpanel.add(scrollPane2);
                scrollPane2.setBounds(70, 65, 880, 515);

                //---- addOrder ----
                addOrder.setText("\u53bb\u7ed3\u7b97");
                addOrder.addActionListener(e -> addOrderActionPerformed(e));
                carpanel.add(addOrder);
                addOrder.setBounds(720, 600, 205, 55);

                //---- delCar ----
                delCar.setText("\u5220\u9664\u9009\u4e2d");
                delCar.addActionListener(e -> delCarActionPerformed(e));
                carpanel.add(delCar);
                delCar.setBounds(45, 605, 205, 55);

                //---- F5_1 ----
                F5_1.setText("\u5237\u65b0");
                carpanel.add(F5_1);
                F5_1.setBounds(new Rectangle(new Point(885, 20), F5_1.getPreferredSize()));

                //---- selectAll ----
                selectAll.setText("\u5168\u9009");
                selectAll.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 24));
                selectAll.addActionListener(e -> selectAllActionPerformed(e));
                carpanel.add(selectAll);
                selectAll.setBounds(70, 5, 100, 50);

                { // compute preferred size
                    Dimension preferredSize = new Dimension();
                    for(int i = 0; i < carpanel.getComponentCount(); i++) {
                        Rectangle bounds = carpanel.getComponent(i).getBounds();
                        preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                        preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                    }
                    Insets insets = carpanel.getInsets();
                    preferredSize.width += insets.right;
                    preferredSize.height += insets.bottom;
                    carpanel.setMinimumSize(preferredSize);
                    carpanel.setPreferredSize(preferredSize);
                }
            }
            ClientPane1.addTab("\u7ba1\u7406\u8d2d\u7269\u8f66", carpanel);

            //======== orderpanel ========
            {
                orderpanel.setLayout(null);
                orderpanel.add(scrollPane3);
                scrollPane3.setBounds(40, 30, 930, 545);

                //---- F5 ----
                F5.setText("\u5237\u65b0");
                orderpanel.add(F5);
                F5.setBounds(new Rectangle(new Point(915, 0), F5.getPreferredSize()));

                { // compute preferred size
                    Dimension preferredSize = new Dimension();
                    for(int i = 0; i < orderpanel.getComponentCount(); i++) {
                        Rectangle bounds = orderpanel.getComponent(i).getBounds();
                        preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                        preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                    }
                    Insets insets = orderpanel.getInsets();
                    preferredSize.width += insets.right;
                    preferredSize.height += insets.bottom;
                    orderpanel.setMinimumSize(preferredSize);
                    orderpanel.setPreferredSize(preferredSize);
                }
            }
            ClientPane1.addTab("\u8ba2\u5355\u7ba1\u7406", orderpanel);

            //======== ideapanel ========
            {
                ideapanel.setLayout(null);

                //---- ideaSubmit ----
                ideaSubmit.setText("\u63d0\u4ea4\u610f\u89c1");
                ideaSubmit.addActionListener(e -> ideaSubmitActionPerformed(e));
                ideapanel.add(ideaSubmit);
                ideaSubmit.setBounds(new Rectangle(new Point(820, 520), ideaSubmit.getPreferredSize()));

                //======== scrollPane1 ========
                {

                    //---- ideaContent ----
                    ideaContent.setText("\u8bf7\u8f93\u5165\u5546\u57ce\u9700\u8981\u4e0a\u67b6\u7684\u65b0\u4e66,\u7ba1\u7406\u5458\u4f1a\u53ca\u65f6\u56de\u590d");
                    scrollPane1.setViewportView(ideaContent);
                }
                ideapanel.add(scrollPane1);
                scrollPane1.setBounds(220, 445, 525, 195);

                //======== scrollPane4 ========
                {

                    //---- table3 ----
                    table3.setModel(new DefaultTableModel(
                        new Object[][] {
                            {"1", "1", "1", "1", "1"},
                            {null, null, null, null, null},
                        },
                        new String[] {
                            null, null, null, null, null
                        }
                    ));
                    scrollPane4.setViewportView(table3);
                }
                ideapanel.add(scrollPane4);
                scrollPane4.setBounds(45, 15, 920, 365);
                ideapanel.add(textArea2);
                textArea2.setBounds(new Rectangle(new Point(20, 125), textArea2.getPreferredSize()));
                ideapanel.add(ideaTitle);
                ideaTitle.setBounds(220, 395, 525, ideaTitle.getPreferredSize().height);

                //---- label3 ----
                label3.setText("\u610f\u89c1\u6807\u9898");
                ideapanel.add(label3);
                label3.setBounds(151, 399, 55, label3.getPreferredSize().height);

                //---- label5 ----
                label5.setText("\u610f\u89c1\u5185\u5bb9");
                ideapanel.add(label5);
                label5.setBounds(150, 445, 50, label5.getPreferredSize().height);

                //---- F6 ----
                F6.setText("\u5237\u65b0");
                ideapanel.add(F6);
                F6.setBounds(890, 400, 78, 30);

                { // compute preferred size
                    Dimension preferredSize = new Dimension();
                    for(int i = 0; i < ideapanel.getComponentCount(); i++) {
                        Rectangle bounds = ideapanel.getComponent(i).getBounds();
                        preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                        preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                    }
                    Insets insets = ideapanel.getInsets();
                    preferredSize.width += insets.right;
                    preferredSize.height += insets.bottom;
                    ideapanel.setMinimumSize(preferredSize);
                    ideapanel.setPreferredSize(preferredSize);
                }
            }
            ClientPane1.addTab("\u610f\u89c1\u53cd\u9988", ideapanel);

            //======== panel1 ========
            {
                panel1.setLayout(null);

                //---- exitButton ----
                exitButton.setText("\u9000\u51fa\u767b\u5f55");
                exitButton.setFont(exitButton.getFont().deriveFont(exitButton.getFont().getSize() + 20f));
                exitButton.addActionListener(e -> exitButtonActionPerformed(e));
                panel1.add(exitButton);
                exitButton.setBounds(310, 380, 380, 125);

                //---- revise ----
                revise.setText("\u4fee\u6539\u8d26\u6237");
                revise.setFont(revise.getFont().deriveFont(revise.getFont().getSize() + 20f));
                revise.addActionListener(e -> reviseActionPerformed(e));
                panel1.add(revise);
                revise.setBounds(310, 110, 380, 125);

                { // compute preferred size
                    Dimension preferredSize = new Dimension();
                    for(int i = 0; i < panel1.getComponentCount(); i++) {
                        Rectangle bounds = panel1.getComponent(i).getBounds();
                        preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                        preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                    }
                    Insets insets = panel1.getInsets();
                    preferredSize.width += insets.right;
                    preferredSize.height += insets.bottom;
                    panel1.setMinimumSize(preferredSize);
                    panel1.setPreferredSize(preferredSize);
                }
            }
            ClientPane1.addTab("\u7528\u6237\u7ba1\u7406", panel1);
        }
        contentPane.add(ClientPane1);
        ClientPane1.setBounds(0, 5, 1035, 715);

        { // compute preferred size
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < contentPane.getComponentCount(); i++) {
                Rectangle bounds = contentPane.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = contentPane.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            contentPane.setMinimumSize(preferredSize);
            contentPane.setPreferredSize(preferredSize);
        }
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JTabbedPane ClientPane1;
    private JPanel bookpanel;
    private JPanel showBookJpanel;
    private JButton FirstPage;
    private JButton previousPage;
    private JButton nextPage;
    private JButton endPage;
    private JLabel label13;
    private JLabel currentPage;
    private JLabel label1;
    private JLabel showLevel;
    private JLabel label2;
    private JLabel totalPage;
    private JLabel label4;
    private JTextField searchBar;
    private JButton search;
    private JLabel userImg;
    private JButton F7;
    private JPanel carpanel;
    private JScrollPane scrollPane2;
    private JPanel carPanel;
    private JButton addOrder;
    private JButton delCar;
    private JButton F5_1;
    private JRadioButton selectAll;
    private JPanel orderpanel;
    private JScrollPane scrollPane3;
    private JButton F5;
    private JPanel ideapanel;
    private JButton ideaSubmit;
    private JScrollPane scrollPane1;
    private JTextArea ideaContent;
    private JScrollPane scrollPane4;
    private JTable table3;
    private JTextArea textArea2;
    private JTextField ideaTitle;
    private JLabel label3;
    private JLabel label5;
    private JButton F6;
    private JPanel panel1;
    private JButton exitButton;
    private JButton revise;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
